#include <stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef int ElementType;
typedef struct Node {
    ElementType data;
	ElementType envus;
   struct Node  *next; 
}Node,*LinkList;
int Creat(LinkList L)
{
	Node *p=L;
	int d,s;
	while((p->next)!=NULL){
		p=p->next;
	}
	char ch;
	do{scanf("%d%d",&d,&s);
	Node *lp=(Node*)malloc(sizeof(Node));
		if(lp==NULL)
			return   -2;
		lp->data=d;
		lp->envus=s;
		p->next=lp;
		lp->next=NULL;
		p=p->next;
	}while((ch=getchar())!='\n');
	return  1;
}

void daoshu(LinkList A,LinkList B){
	Node *pa,*pb;
	pa=A->next;
	pb=B;
	while(pa&&pb){
		if(pa->envus>0)
			{pa->data=pa->data*pa->envus;
			pa->envus=pa->envus-1;
			pb->next=pa;pb=pb->next;}
		else{pb->next=NULL;
		}
	pa=pa->next;
	}
	pb->next=NULL;
	 A->next=NULL;
}
void ListPrint(LinkList L)
{
    Node *p=L->next; 
    if(p==NULL)
        printf("0 0");
    while(p!=NULL)
    {
        if(p->next!=NULL)
			printf("%d %d ",p->data,p->envus);
        else
			printf("%d %d",p->data,p->envus);
        p=p->next;
    }
}
int main()
{	LinkList ai,bi,ci;
    ai=(LinkList)malloc(sizeof(Node));
    if(ai==NULL)
        return -2;
    ai->next=NULL;
    bi=(LinkList)malloc(sizeof(Node));
    if(bi==NULL)
        return -2;
    bi->next=NULL;
    ci=(LinkList)malloc(sizeof(Node));
    if(ci==NULL)
        return -2;
    ci->next=NULL;
    Creat(ai);
	daoshu(ai,bi);
    ListPrint(bi);
	system("pause");
    return 0;
}
